package com.appkubes.fintech.admin.application.bill.controller;

import com.appkubes.fintech.admin.application.bill.entity.dto.BillReportDTO;
import com.appkubes.fintech.admin.application.bill.entity.dto.BillReportVO;
import com.appkubes.fintech.admin.application.bill.entity.dto.RepayVO;
import com.appkubes.fintech.admin.application.bill.service.RentBillHeaderService;
import com.appkubes.fintech.admin.application.bill.entity.vo.RentBillHeaderRequest;
import com.appkubes.fintech.admin.application.bill.entity.dto.RentBillHeaderDTO;
import com.appkubes.fintech.common.response.Response;
import com.appkubes.fintech.core.po.FintechRentOrder;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

/*
 *
 * @author xqc
 * @date 	2020/01/03 19:02:40
 */
@RestController
@RequestMapping("rent/rentBillHeader")
@Api(tags = "账单列表", value = "RentBillHeaderController")
@Slf4j
public class RentBillHeaderController {

    @Autowired
    private RentBillHeaderService rentBillHeaderService;


    @ApiOperation(tags = "分页账单列表", value = "queryPage")
    @PostMapping(value = "queryPage")
    public Response<PageInfo<RentBillHeaderDTO>> queryPage(@RequestBody RentBillHeaderRequest rentBillHeaderRequest) {

        PageInfo<RentBillHeaderDTO> pageInfo = rentBillHeaderService.queryPage(rentBillHeaderRequest);
        return Response.success(pageInfo);
    }

    @ApiOperation(tags = "更新账单列表", value = "update")
    @PostMapping(value = "update")
    public Response update(@RequestBody RentBillHeaderRequest rentBillHeaderRequest) {

        return rentBillHeaderService.update(rentBillHeaderRequest);
    }

    @ApiOperation(tags = "删除账单列表", value = "delete")
    @PostMapping(value = "delete")
    public Response delete(String id) {
        return rentBillHeaderService.deleteRentBillHeader(id);
    }

    @ApiOperation(tags = "获取账单列表", value = "getById")
    @GetMapping(value = "getById")
    public Response<RentBillHeaderDTO> getById(String id) {
        return rentBillHeaderService.getById(id);

    }


    @ApiOperation("线下还款")
    @PostMapping("/repay")
    public Response repay(@RequestBody  RepayVO vo) {
        if(StringUtils.isBlank(vo.getBillKey())){
            return Response.fail("账单key不能空");
        }
        if(StringUtils.isBlank(vo.getRepayType())){
            return Response.fail("类型不能空");
        }
     /*   if(Objects.isNull(vo.getPayAmt())||vo.getPayAmt().compareTo(BigDecimal.ZERO)<0){
            return Response.fail("支付金额不能空");
        }*/
       Response response=rentBillHeaderService.repay(vo);
        return response;
    }

    @ApiOperation("线下还款")
    @PostMapping("/reportBill")
    public Response<List<BillReportDTO>> reportBill(@RequestBody BillReportVO vo) {
        Response response=rentBillHeaderService.billReport(vo);
        return response;
    }
}
